//
//  NSString+Ext.m
//  MyLib
//
//  Created by zhuyechao on 18/04/2017.
//  Copyright © 2017 zyc. All rights reserved.
//

#import "NSString+Ext.h"

@implementation NSString (Ext)

- (NSString *)replace:(NSString *)target withString:(NSString *)replacement {
    return [self stringByReplacingOccurrencesOfString:target withString:replacement];
}

- (NSString *)substring:(NSUInteger)from to:(NSUInteger)to {
    if (to <= from)
        return nil;
    NSRange range = NSMakeRange(from, to - from + 1);
    return [self substringWithRange:range];
}

- (NSString *)substring:(NSUInteger)from length:(NSUInteger)length {
    if (length <= 0)
        return nil;
    NSRange range = NSMakeRange(from, length);
    return [self substringWithRange:range];
}

- (BOOL)startWith:(NSString *)prefix {
    return [self hasPrefix:prefix];
}

- (BOOL)endWith:(NSString *)suffix {
    return [self hasSuffix:suffix];
}

- (BOOL)contains:(NSString *)str {
    NSRange range = [self rangeOfString:str];
    return range.location != NSNotFound;
}

@end
